package com.cxs.plan.controller.power;

import com.cxs.plan.domain.HttpResult;
import com.cxs.plan.DTO.MenuDTO;
import com.cxs.plan.domain.entity.Menu;
import com.cxs.plan.service.MenuService;
import com.cxs.plan.utils.PageUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin")
@Tag(name = "菜单管理")
public class MenuController {

    @Autowired
    private MenuService menuService;
    @Autowired
    private PageUtil pageUtil;

    @Operation(summary = "菜单列表")
    @GetMapping("/menu")
    public HttpResult getMenuList() {
        List<MenuDTO> menuList = menuService.getMenuList();
        return HttpResult.success(menuList);
    }

    @Operation(summary = "添加菜单")
    @PostMapping("/menu")
    public HttpResult addMenu(@Validated @RequestBody Menu menu) {
        menuService.addMenu(menu);
        return HttpResult.success();
    }

    @Operation(summary = "删除菜单")
    @DeleteMapping("/menu/{id}")
    public HttpResult deleteMenu(@PathVariable("id") Long id) {

        menuService.delMenuById(id);
        return HttpResult.success();
    }
}
